#include<stdio.h>
#include<string.h>

int main(int argc, char* argv[])
{
    switch(argc)
    {
        case 2:
            break;
        case 4:
            if('2' == argv[2][0])
            {
                break;
            }
        default:
            printf("Please check the arguments !\n");
            return 1;
    }
    FILE* reader, *writer;
    reader = fopen(argv[1], "r");
    if(NULL == reader)
    {
        printf("No exists the file \"%s\". \n", argv[1]);
        return 1;
    }
    if(4 == argc)
    {
        writer = fopen(argv[3], "w");
        if(NULL == writer)
        {
            printf("Error in writing !");
            return 1;
        }
    }
    char line[1024];
    while(!feof(reader))
    {
        fgets(line, sizeof(line), reader);
        if( 0 < strlen(line))
        {
            line[strlen(line) - 1] = '\0';
        }
        if(4 == argc)
        {
            fprintf(writer, "%s\n", line); 
        }
        else
        {
            printf("%s\n", line);
        }
    }
    if(4 == argc)
    {
        fclose(writer);
    }
    fclose(reader);
    return 0;
}
